<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- 
<h5 class=" txt-color-blueDark hidden-tablet"><i class="fa fa-fw fa-arrow-right"></i> <s:property value="department.name"/>  &nbsp;</h5>
 -->
<input type="hidden" id="keyId" name="keyId" value="<s:property value="keyId"/>"/>
<table id="ajax_dict_list_table" class="table table-striped table-hover">
	<tbody>
		<s:iterator value="listMap" id="list">
			<s:if test="#list != null">
			<tr id="<s:property value="#list.id"/>" 
					<s:if test="#list.dutyDefault == 1"> class="unread" </s:if>
				>
				<!-- 
				<td  class="inbox-table-icon">
					<div class="checkbox">
					<label>
						<input type="checkbox" class="checkbox style-2">
						<span></span> </label>
					</div>
				</td> -->
				<td  class="inbox-data-date hidden-xs hidden-sm" >
					<div>
						<s:property value="#list.name"/> 
					</div>
				</td>
				<!-- 未添加显示当前组，已添加显示 已添加 -->
				<td  class=" hidden-xs hidden-sm">
					<s:if test="#list.dutyDefault == 1">
						<span class="label bg-color-teal">已添加</span>
						<s:if test="#list.principal == 1">
							<span class="label bg-color-teal"><i class="fa  fa-star"></i> 负责人</span>
						</s:if>
						<span class="label label-warning"><s:property value="#list.department"/></span> 
					</s:if>
					<s:else>
						<div>
							当前组 <span class="label label-warning"> <s:property value="#list.department"/> </span> 
						</div>
					</s:else>
				</td>
				<td>
					<div>
						<s:if test="#list.dutyDefault == 1">
							<a key="ajax_members_actions_delete" data="<s:property value="#list.dutyId"/>" class="btn btn-default " href="javascript:void(0);"><i class="fa fa-lg fa-minus"></i> 从该组去除</a>
							<s:if test="#list.principal != 1">
								<a key="ajax_members_actions_principal" data="<s:property value="#list.dutyId"/>" class="btn btn-default " href="javascript:void(0);"><i class="fa fa-lg fa-star"></i> 设为负责人</a>
							</s:if>
							<s:else>
								<a key="ajax_members_actions_noprincipal" data="<s:property value="#list.dutyId"/>" class="btn btn-default " href="javascript:void(0);"><i class="fa fa-lg fa-star-half-o"></i> 取消负责人</a>
							</s:else>
						</s:if>
						<s:else>
							<a key="ajax_members_actions_add" data="<s:property value="#list.dutyId"/>" class="btn btn-default " href="javascript:void(0);"><i class="fa fa-lg fa-plus"></i> 添加到该组</a>
						</s:else>
					</div>
				</td>
			</tr>
			</s:if>
			
		</s:iterator>
	</tbody>
</table>

<script>

	//members add
	$("a[key=ajax_members_actions_add]").click(function() {
		var this_tr = $(this).parent().parent().parent();
        var data={keyId:$("input#keyId").val(),userId:$(this_tr).attr("id"),dutyId:$(this).attr("data")};
        ajax_action("ajax-department!membersAddOrRemove.action",data,null,function(pdata){
            _show(pdata);
            loadURL("ajax-department!members.action?keyId="+$("input#keyId").val(), $('#inbox-content > .table-wrap'));
        });
	});
	//members delete
	$("a[key=ajax_members_actions_delete]").click(function() {
        var this_tr = $(this).parent().parent().parent();
        var data={keyId:$("input#keyId").val(),userId:$(this_tr).attr("id"),dutyId:$(this).attr("data")};
        ajax_action("ajax-department!membersAddOrRemove.action",data,null,function(pdata){
            _show(pdata);
            loadURL("ajax-department!members.action?keyId="+$("input#keyId").val(), $('#inbox-content > .table-wrap'));
        });
	});
	//members principal
	$("a[key=ajax_members_actions_principal]").click(function() {
		var this_tr = $(this).parent().parent().parent();
        var dutyId=$(this).attr("data");
		fn_members_action($(this_tr).attr("id"),"principal",dutyId);
	});
	//ajax_members_actions_noprincipal
	$("a[key=ajax_members_actions_noprincipal]").click(function() {
		var this_tr = $(this).parent().parent().parent();
        var dutyId=$(this).attr("data");
		fn_members_action($(this_tr).attr("id"),"noprincipal",dutyId);
	});

	//Gets tooltips activated
	$("#inbox-table [rel=tooltip]").tooltip();
	$("#inbox-table input[type='checkbox']").change(function() {
		$(this).closest('tr').toggleClass("highlight", this.checked);
	});
	$("#inbox-table .inbox-data-message").click(function() {
		$this = $(this);
	})
	$("#inbox-table .inbox-data-from").click(function() {
		$this = $(this);
	})
	$('.inbox-table-icon input:checkbox').click(function() {
		enableDeleteButton();
	})
	$(".deletebutton").click(function() {
		$('#inbox-table td input:checkbox:checked').parents("tr").rowslide();
		//$(".inbox-checkbox-triggered").removeClass('visible');
		//$("#compose-mail").show();
	});
	function enableDeleteButton() {
		var isChecked = $('.inbox-table-icon input:checkbox').is(':checked');

		if (isChecked) {
			$(".inbox-checkbox-triggered").addClass('visible');
			//$("#compose-mail").hide();
		} else {
			$(".inbox-checkbox-triggered").removeClass('visible');
			//$("#compose-mail").show();
		}
	}
	
</script>
